import axios from 'axios'
import { Toast } from 'vant'

const http = axios.create({
  timeout: 10000,
})
/* 拦截器功能 */

// 在发请求之前拦截 -- showLoading
http.interceptors.request.use(function (config) {
  Toast.loading({
    message: '加载中...',
    forbidClick: true,
    duration: 0
  })
  return config
}, function (error) {
  return Promise.reject(error)
}
)

// 在成功后拦截 -- hideLoading
http.interceptors.response.use(function (response) {
  // 隐藏
  Toast.clear()
  return response
}, function (error) {
  return Promise.reject(error)
}
)

export default http
